/**  
 * @date 2023-12-06 
 * @author Zhang Yu
 */
package com.springboot.template.service;
import java.util.UUID;

import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

/**  
 * @description: TODO
 */
@Service
public class MyService {

    @Cacheable(value = "token", key = "#key")
    public String setData(String key) {
        // 如果缓存中存在数据，则直接返回缓存数据，否则执行方法体，并将结果缓存
        return fetchDataFromDatabase(key);
    }

    private String fetchDataFromDatabase(String key) {
        UUID uuid = UUID.randomUUID();
        System.out.println(uuid);
        // 实际从数据库获取数据的逻辑
        return uuid.toString();
    }
}
